package com.hualan.mapper;

import com.hualan.pojo.Huifudayi;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface HuifudayiMapper {
    @Select(value = "select n.*, m.nickname toname from (SELECT h.*, u.nickname nickname from huifudayi h join users u on h.uid = u.id where h.pid = #{pid}) n left join (SELECT h.*, u.nickname nickname from huifudayi h join users u on h.uid = u.id where h.pid = #{pid}) m on n.hid = m.id ")
    List<Huifudayi> listById(@Param("pid") Integer pid);
    List<Huifudayi> listByPids(@Param("pids") List<Integer> pids);
    @Insert(value = "insert into huifudayi (pid,hid,uid,content,time) value(#{h.pid},#{h.hid},#{h.uid},#{h.content},#{h.time})")
    Integer add(@Param("h") Huifudayi huifudayi);
    @Select(value = "select h.*, u.nickname from huifudayi h join users u on h.uid = u.id  where hid in (select id from huifudayi where uid = #{uid})")
    List<Huifudayi> listToMe(@Param("uid") Integer uid);

}
